# makefile - for GNU
#
# modification history
# --------------------
# 03k,30oct00,sn   _NO_HYPOT is now the default behaviour in complext.h
#                  do provide long double support
# 03j,26oct00,bc   Disable MRI desc in assembler docs.
# 03i,05oct00,ish  test if we have created ldscripts directory
# 03h,02oct00,ish  Create ldscripts directory if it's not here
# 03g,25aug00,bc   try deleting index.html copying.  Clean up as.html output.
# 03f,22aug00,mrs  Add solaris2.7 native support; add -O2 to library builds.
# 03e,19aug00,tdl  changed vxworks6 to vxworksae
# 03d,08aug00,ish  add ldscripts directory copy to
#                  .../host/$WIND_HOST_TYPE/lib/ldscripts
# 03c,20mar00,sn   Ensure target/h is the first include path when we
#                  build libgcc2.c
# 03b,17mar00,ish  Correct TARGETS variables in general.
# 03a,07mar00,bc   Add CC and MAKE definitions for Linux.
# 02z,26feb00,bc   Delete simso references, spell linux WIND_HOST_TYPE right.
# 02y,18feb00,bc   Add Linux host support
# 02x,30jan00,bc   Add HTML doc-build code.
# 02w,30jan00,bc   Add make invocation variable to suppress makeinfo errors.
# 02v,17nov99,sn   Pass down correct target flags for C++
# 02u,15nov99,sn   added new make targets (as<arch>, cc<arch> etc.)
#                  ensure that the only languages we configure are c, c++
# 02t,05nov99,bc   Avoid Makefile.orig generation in host/src/gnu.
# 02s,21okt99,tpw  redo tdel's hppa2.0 change.
# 02r,06okt99,tdl  i386 rule will now build ccpentium
#		   i386-orig will build the original i386
# 02q,30sep99,tdl  prepare pentium triple
# 02p,30sep99,tdl  setting WIND_BASE to /wind/river now...
# 02o,15sep99,mrs  Fix perms problems and make more robust
# 02n,28jul99,tdl  added sparc-elf-dwarf support
# 02m,01aug99,mrs  Merge intel p2 project branch to main branch.
# 02l,14jul99,jld  Add support for MCORE
# 02k,13jul99,tdl  fix "tar" problem on solaris
# 02j,08jul99,tdl  set CFLAGS when x86-win32 and ...-vxworks6 too
# 02i,06jul99,sn   insulate ourselves from the environment we were
#                  invoked with.
# 02h,25jun99,tdl  p.d. compilers now default to elf/dwarf
# 02g,15jun99,sn   removed uses of "$@" invalidated by last change
# 02f,15jun99,sn   add targets of the form <arch>-<omf>-<debug>
#                  <arch> targets now default to Tor2.0 omf/debug format
#                  e.g arm defaults to arm-coff-stabs
# 02f,14may99,jld  added new Cygwin-specific stuff and cleaned up a bit.
# 02e,23apr99,mrs  Fix thumbe -> thumb.
# 02d,05apr99,bc   add ELF build calls for ARM, 386, mips, ppc
# 02c,21jan99,tdl  added thumb everywhere
# 02b,05jan99,bc   try building sh.
# 02a,18dec98,bc   Add aliases for target names, add x86-linux host type,
#                  translate HOST to HOST, add 'all' target, delete
#		   Tornado 2.0 copying of the Tornado 1.0.1 C compiler.
# 01ad,25sep98,tdl added arm
# 01ac,28jul98,tdl derived from gnu.cpp makefile
# 01ab,15jul98,tdl ppc now alias for powerpc - now compatible with upper
#		   level Makefile.w32 where ppc is used
# 01aa,14jul98,sn  copy PPC compiler from wrs.tor1_0_1.patch-spr20257
# 01z,08jul98,tdl added copy of frozen make for x86-win32
# 01y,24jun98,tdl remove BUILD_DIR from x86-win32 build, added -e for x86-win32
# 01x,22jun98,tdl conditional prebuild and copy of as and ld for x86-win32
# 01w,22jun98,jld build win32 stuff on local D: drive.
# 01v,19jun98,sn  run configure under $(GNU_CONFIG_SHELL)
#		  fix up $(BUILD_DIR)/Makefile to work around
#		  cygwin bash bug (only affects x86-win32 builds)
# 01u,06mar98,sn  pass --with-cross-host to configure to force
#                 the simso build to install libstdc++.a in
#                 the correct place.
# 01t,02mar98,sn  use make from /vobs/wpwr/native
# 01s,30mar98,sn  hardcoded CC_CYGNUS_VER
#                 copy simso compiler from sparc-sun-solaris2.4 even on
#                 non-2.4 hosts
# 01r,27mar98,sn  added support for hpux10(.20)
# 01q,13mar98,sn  unified builder and simso_builder
#                 removed dependency on host/include/make files
#                 install Sirocco C compilers
#                 general cleanup (ripped off from jld and tpw)
# 01p,16oct97,jld pass CFLAGS to sub-makes; invoke ./config.guess with path.
# 01o,10jan97,yp  made special builder for simso so CC_FOR_TARGET can be passed
# 01n,23oct96,pr  added simso support (Ian changes went lost).
# 01m,19nov96,p_m defined compilers to build on a per host basis
# 01l,05nov96,p_m made sparc and hppa targets conditional
# 01k,18sep96,p_m use mkdir -p to create the build directories since two
#                 successive mkdir generated an error now that make exits
#                 if a sub shell fails.
# 01j,20aug96,ism fixed simso support (only compiles on solaris)
# 01i,13may96,ism added simso support
# 01h,12feb96,yp  changed to inherit TOOLCHAIN def.
# 01g,28nov95,mem added mips support
# 01f,27sep95,jcf added i960 support to VX_TARGETS
# 01e,25sep95,yp  added i960 support
# 01d,15jun95,yp  accomodated passing $(CC) to build. added rules for native
#		  tools build
# 01c,14jun95,p_m moved comments out of builder rule.
# 01b,11jun95,yp  passed $(HOST) make recursion. cleaned up
#		  --program-transform-name
# 01a,24may95,yp  derived from vxgdb/Makefile

# DESCRIPTION
# This file contains makefile rules for WRS local builds of GNU tools
# for each target we support. It is called "makefile" with a little
# "m" to avoid confusion with the GNU "Makefile" with a capital "M"
# that would normally reside in the top-level directory.  Since
# *this* makefile uses VPATH to build each target in a sub-dir
# there never will be a "Makefile" created in the top-level dir.
#
# The following make targets are available: (see $($(HOST)_TARGETS)
# for possible values of <arch>).
#
#    <arch>		- everything
#    as<arch>		- assembler
#    cc<arch>		- compiler (but not libgcc)
#    ld<arch>		- linker
#    binutils-<arch>	- binutils
#    libgcc-<arch>	- libgcc
#    libs-<arch>	- libraries such as libstdc++.a
#    nolibs-<arch>      - assembler, compiler, linker, binutils

###############################################################################
# This makefile consists of several levels each of which recursively
# invokes the next.
#
# The top-level is invoked as
#
# make <arch> ... <arch>
#
# e.g., make ppc arm.
#
# This level defines a basic environment (WIND_BASE, HOST, PATH,
# CANONICAL_TARGET and TARGET_SUFFIX) which it exports to the next "builder"
# level(s). It sets RLEVEL=builder so that inner levels can tell they are
# inner levels. On Windows some of this environment is inherited from our
# invoker (Makefile.w32).
#
# The builder and subbuilder levels define other make variables in terms of
# the basic environment. Note however that all variables can be overidden
# by the top-level invocation (for example make ppc GNU_TARGETS=all-gcc
# should work).
#
# The builder level runs `configure' and makes any necessary
# adjustments to the generated build tree.
#
# The subbuilder level builds each GNU_TARGET in turn.

ifneq ($(RLEVEL),builder)

###############################################################################
# This is the top-level. We were invoked with a list of target
# architectures: our job is to deduce WIND_BASE, HOST,
# PATH, CANONICAL_TARGET, and TARGET_SUFFIX, and export them to the
# next "builder" level. This is done for each
# target in sequence because that's the way `make' works.
#
# Before finishing we define RLEVEL = builder so that
# inner levels can tell that they are inner levels.

# := is a GNUism that means "evaluate the RHS right away using
# the current values of any variables and without recursive
# expansion." We use it throughout this makefile.

HOST		:= \
	$(shell \
		/bin/sh ./config.guess | \
	 	sed 's/sparc-sun-solaris2.[0-9.]*$$/sun4-solaris2/' | \
		sed 's/sparc-sun-sunos4.1.4/sun4-sunos4/' | \
		sed 's/hppa1.1-hp-hpux\([0-9]*\)\.[0-9]*/parisc-hpux\1/' | \
		sed 's/hppa2.0-hp-hpux\([0-9]*\)\.[0-9]*/parisc-hpux\1/' | \
		sed 's/i[0-9]*-pc-cygwin.*/x86-win32/' | \
		sed 's/i[0-9]*-pc-linux-gnu/x86-linux2/' \
	)

export HOST

# Host specific stuff: right now much (but not all) of the x86-win32
# environment comes in from Makefile.w32, while the unix environment
# is set here. For example WIND_BASE can be assumed to be
# set already if we're on Windows.

ifneq ($(HOST),x86-win32)

# Unix specific stuff

ifneq ($(filter sun%,$(HOST)),)
CCS		= /usr/ccs/bin	# Sun
else
CCS             =		# !Sun
endif

#WIND_BASE	:= $(shell cd ../../../../wpwr; pwd)
WIND_BASE	:= $(shell cd ../../../../../wind/river; pwd)
#WIND_BASE	:= /wind/river
export WIND_BASE

PATH		:= $(WIND_BASE)/native/$(HOST)/bin:/folk/gnu/H-$(HOST)/bin
PATH		:= $(PATH):$(CCS)/bin:/usr/bin:/usr/ucb:/usr/ucb/bin

ifeq ($(shell uname -r),5.7)
PATH		:= $(WIND_BASE)/native/sun4-solaris2.7/bin:$(PATH)
endif
export PATH

else

# Cygwin-specific stuff.

# Make sure we're not using some installed bin dir. Sadly, the following
# solution also removes non-Cygwin `bin' dirs.

PATH		:= \
	${shell \
		IFS=: ; \
		newpath=/bin; \
		for segment in $$PATH; do \
			case $$segment in \
			*/bin) ;; \
			*) newpath="$$newpath:$$segment" ;; \
			esac; \
		done; \
		echo "$$newpath" \
	}
export PATH


endif	# host specific stuff

RLEVEL=builder
export RLEVEL

else   # RLEVEL != builder

###############################################################################
# This is either builder or subbuilder: we can assume WIND_BASE,
# HOST, PATH and CANONICAL_TARGET are defined.

GNU_CONFIG_SHELL= /bin/sh
GNU_BUILD_SHELL	= $(GNU_CONFIG_SHELL)

MAKE		= make
CFLAGS 		= -O2

CFLAGS_FOR_TARGET = -include $(WIND_BASE)/target/h/vxWorks.h -O2
CXXFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)
LIBCXXFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)
# Header file name clashes should be resolved in favor
# of target/h.
LIBGCC2_INCLUDES= -I$(WIND_BASE)/target/h
GNU_TARGETS	= all install

# Build is performed in LOCAL_TARGET_DIR and, if necessary, copied to
# TARGET_DIR.  However, please only override the parent dir paths, HOST_DIR
# and LOCAL_HOST_DIR.  Override DIRCOPY to `true' to suppress copying
# competely.
SRC_DIR		= $(WIND_BASE)/host/src/gnu
INSTALL_DIR	= $(WIND_BASE)/host/$(HOST)
SCRIPTS_INSTALL = $(INSTALL_DIR)/lib/ldscripts
MAKE_SCRIPTS	= { test -d "$(SCRIPTS_INSTALL)" || mkdir -p "$(SCRIPTS_INSTALL)"; }
HOST_DIR	= $(SRC_DIR)/$(HOST)
TARGET_DIR	= $(HOST_DIR)/$(CANONICAL_TARGET)
LOCAL_HOST_DIR	= $(SRC_DIR)/$(HOST)
LOCAL_TARGET_DIR= $(LOCAL_HOST_DIR)/$(CANONICAL_TARGET)
MAKE_COPYDIR	= { test -d "$(TARGET_DIR)" || mkdir -p "$(TARGET_DIR)"; }
DIRCOPY		= $(MAKE_COPYDIR) && { (cd $(LOCAL_HOST_DIR) && \
		  tar cf - $(CANONICAL_TARGET)) | (cd $(HOST_DIR) && tar xf -) } && chmod -R u+w $(HOST_DIR)

EXE		=

ifeq ($(HOST),x86-win32)

# Cygwin-specific stuff.

# This suffix is only used in this makefile; the GNU Makefile's have their
# own mechanisms.
EXE		= .exe

# For PowerPC, the B19 Cygwin build compiler suffers an unknown signal at -O2
# when compiling tc-ppc.c.

PPC_W32_CFLAGS	= -O1

# non-dwarfized
ifeq (powerpc-wrs-vxworks,$(CANONICAL_TARGET))
CFLAGS		= $(PPC_W32_CFLAGS)
endif

# ...and dwarfized
ifeq (powerpc-wrs-vxworksae,$(CANONICAL_TARGET))
CFLAGS		= $(PPC_W32_CFLAGS)
endif

endif # Cygwin specific stuff

ifeq ($(HOST),x86-linux2)
# Linux-specific stuff

DIRCOPY		= true

endif # Linux specific stuff

endif # RLEVEL = builder

sun4-sunos4_TARGETS	= arm thumb ppc pentium mips sh sparc

x86-linux2_TARGETS	= arm thumb ppc pentium mips sh

sun4-solaris2_TARGETS	= arm thumb ppc pentium mips sh sparc

parisc-hpux10_TARGETS	= arm thumb ppc pentium mips sh hppa

x86-win32_TARGETS	= arm thumb ppc pentium mips sh


all default:	$($(HOST)_TARGETS)

all_TARGETS		= $(subst ppc,ppc powerpc,$($(HOST)_TARGETS))
all_ASSEMBLERS		= $(foreach arch,$(all_TARGETS),as$(arch))
all_COMPILERS		= $(foreach arch,$(all_TARGETS),cc$(arch))
all_LIBGCC		= $(foreach arch,$(all_TARGETS),libgcc-$(arch))
all_LINKERS		= $(foreach arch,$(all_TARGETS),ld$(arch))
all_BINUTILS		= $(foreach arch,$(all_TARGETS),binutils-$(arch))
all_LIBS		= $(foreach arch,$(all_TARGETS),libs-$(arch))
all_NOLIBS		= $(foreach arch,$(all_TARGETS),nolibs-$(arch))

LIBGCC=stmp-multilib
INSTALL_LIBGCC=install-multilib

$(all_ASSEMBLERS) :
	$(MAKE) $(subst as,,$@) \
		GNU_TARGETS="all-gas install-gas" \

$(all_COMPILERS) :
	$(MAKE) $(subst cc,,$@) \
		GNU_TARGETS="small-gcc install-gcc" \
		LIBGCC="null" INSTALL_LIBGCC="null"

$(all_LIBGCC) :
	$(MAKE) $(subst libgcc-,,$@) \
		GNU_TARGETS="all-gcc install-gcc"

$(all_LINKERS):
	$(MAKE) $(subst ld,,$@) \
		GNU_TARGETS="all-ld install-ld"

$(all_BINUTILS):
	$(MAKE) $(subst binutils-,,$@) \
		GNU_TARGETS="all-binutils install-binutils"

$(all_LIBS):
	$(MAKE) $(subst libs-,,$@) \
		GNU_TARGETS="all-target install-target"

$(all_NOLIBS):
	$(MAKE) $(subst nolibs-,,$@) \
		GNU_TARGETS="all-gas install-gas \
                             small-gcc install-gcc \
                             all-ld install-ld \
                             all-binutils install-binutils" \
		LIBGCC="null" INSTALL_LIBGCC="null"		


########################################

arm     : arm-elf-dwarf

arm-coff-stabs:
	$(MAKE)	CANONICAL_TARGET=arm-wrs-vxworks TARGET_SUFFIX=arm builder

arm-elf-dwarf:
	$(MAKE)	CANONICAL_TARGET=arm-wrs-vxworksae TARGET_SUFFIX=arm builder

########################################

thumb   : thumb-elf-dwarf

thumb-coff-stabs:
	$(MAKE)	CANONICAL_TARGET=thumb-wrs-vxworks TARGET_SUFFIX=thumb builder

thumb-elf-dwarf:
	$(MAKE)	CANONICAL_TARGET=thumb-wrs-vxworksae TARGET_SUFFIX=thumb builder

########################################

hppa:
	$(MAKE)	CANONICAL_TARGET=hppa1.1-wrs-vxworks TARGET_SUFFIX=hppa builder

########################################

i386-orig x86-orig : i386-elf-dwarf

i386-aout-stabs x86-aout-stabs :
	$(MAKE) CANONICAL_TARGET=i386-wrs-vxworks TARGET_SUFFIX=386 builder

i386-elf-dwarf x86-elf-dwarf :
	$(MAKE) CANONICAL_TARGET=i386-wrs-vxworksae TARGET_SUFFIX=386 builder

########################################

i386 x86 pentium i586 : pentium-elf-dwarf

pentium-aout-stabs i586-aout-stabs :
	$(MAKE) CANONICAL_TARGET=i586-wrs-vxworks TARGET_SUFFIX=pentium builder

pentium-elf-dwarf i586-elf-dwarf :
	$(MAKE) CANONICAL_TARGET=i586-wrs-vxworksae TARGET_SUFFIX=pentium builder

########################################

i960 960 : i960-coff-coff

i960-coff-coff 960-coff-coff :
	$(MAKE) CANONICAL_TARGET=i960-wrs-vxworks5.3 TARGET_SUFFIX=960 builder

########################################

m68k 68k : m68k-aout-stabs

m68k-aout-stabs 68k-aout-stabs :
	$(MAKE) CANONICAL_TARGET=m68k-wrs-vxworks TARGET_SUFFIX=68k builder

########################################

mcore :
	$(MAKE) CANONICAL_TARGET=mcore-wrs-vxworks TARGET_SUFFIX=mcore builder

########################################

mips   : mips-elf-dwarf

mips-elf-stabs :
	$(MAKE) CANONICAL_TARGET=mips-wrs-vxworks TARGET_SUFFIX=mips builder

mips-elf-dwarf :
	$(MAKE) CANONICAL_TARGET=mips-wrs-vxworksae TARGET_SUFFIX=mips builder

########################################

ppc powerpc : ppc-elf-dwarf

ppc-elf-stabs powerpc-elf-stabs :
	$(MAKE) CANONICAL_TARGET=powerpc-wrs-vxworks TARGET_SUFFIX=ppc \
	builder

ppc-elf-dwarf powerpc-elf-dwarf :
	$(MAKE) CANONICAL_TARGET=powerpc-wrs-vxworksae TARGET_SUFFIX=ppc builder

########################################

sh:
	$(MAKE) CANONICAL_TARGET=sh-wrs-vxworks TARGET_SUFFIX=sh builder

########################################

simso:
	$(MAKE) CANONICAL_TARGET=`/bin/sh ./config.guess` TARGET_SUFFIX=simso \
	"CFLAGS=$(CFLAGS) -DTARGET_VXSIM_SOLARIS" builder

########################################

sparc	: sparc-elf-dwarf

sparc-aout-stabs:
	$(MAKE) CANONICAL_TARGET=sparc-wrs-vxworks TARGET_SUFFIX=sparc builder

sparc-elf-dwarf :
	$(MAKE) CANONICAL_TARGET=sparc-wrs-vxworksae TARGET_SUFFIX=sparc builder

########################################

#  HTML docs are made here, only on Solaris

ifeq ($(HOST),sun4-solaris2)
HTML_INSTALL = $(WIND_BASE)/docs/gnu
GNU_BASE     = $(WIND_BASE)/host/src/gnu
GNU_BUILD    = $(GNU_BASE)/build_docs
ITOOLKIT     = $(HTML_INSTALL)/toolkit
IMAKE        = $(HTML_INSTALL)/make
HTML_DOCS    = $(ITOOLKIT)/cpp.html          \
               $(ITOOLKIT)/cpp_toc.html      \
               $(ITOOLKIT)/gcc.html          \
               $(ITOOLKIT)/gcc_foot.html     \
               $(ITOOLKIT)/gcc_toc.html      \
               $(ITOOLKIT)/as.html           \
               $(ITOOLKIT)/as_foot.html      \
               $(ITOOLKIT)/as_toc.html       \
               $(ITOOLKIT)/gasp.html         \
               $(ITOOLKIT)/gasp_toc.html     \
               $(ITOOLKIT)/ld.html           \
               $(ITOOLKIT)/ld_toc.html       \
               $(ITOOLKIT)/binutils.html     \
               $(ITOOLKIT)/binutils_toc.html \
               $(ITOOLKIT)/iostream.html     \
               $(ITOOLKIT)/license.html      \
               $(IMAKE)/make.html
# Yes, this is an inappropriate place to get this tool from...
TEXI2HTML  = /folk/bcox/.bin/scripts/texi2html
#TEXI2HTML  = /folk/bcox/src/Texi2html/texi2html  slightly better, with bug as well
#TEXI2HTML=/folk/bcox/src/Texi2html-1-60-Beta/texi2html


docs:	   html_docs # pdf_docs (later)

html_docs: html_toc $(HTML_DOCS)


$(ITOOLKIT)/cpp.html $(ITOOLKIT)/cpp_toc.html: $(GNU_BASE)/gcc/cpp.texi
	cd $(ITOOLKIT); $(TEXI2HTML) $<

$(ITOOLKIT)/gcc.html \
$(ITOOLKIT)/gcc_foot.html \
$(ITOOLKIT)/gcc_toc.html: $(GNU_BASE)/gcc/gcc.texi $(GNU_BASE)/gcc/invoke.texi
	cd $(ITOOLKIT); $(TEXI2HTML) $<

$(ITOOLKIT)/as.html \
$(ITOOLKIT)/as_foot.html \
$(ITOOLKIT)/as_toc.html: $(GNU_BASE)/gas/doc/as.texinfo
	cd $(GNU_BUILD); \
	rm -f as.texinfo; \
	ln -s $< as.texinfo; \
	for f in $(GNU_BASE)/gas/doc/c-*.texi; do \
	    rm -f `basename $$f`; \
	    ln -s $$f `basename $$f`; \
	done; \
	sed < $(GNU_BASE)/gas/doc/all.texi > asconfig.texi \
	  -e 's|@set MULTI-OBJ|@clear MULTI-OBJ|' \
	  -e 's|@set BOUT|@clear BOUT|' \
	  -e 's|@set COFF|@clear COFF|' \
	  -e 's|@set SOM|@clear SOM|' \
	  -e 's|@set A29K|@clear A29K|' \
	  -e 's|@set ARC|@clear ARC|' \
	  -e 's|@set D10V|@clear D10V|' \
	  -e 's|@set D30V|@clear D30V|' \
	  -e 's|@set H8/300|@clear 300|' \
	  -e 's|@set H8/500|@clear 500|' \
	  -e 's|@set HPPA|@clear HPPA|' \
	  -e 's|@set I960|@clear I960|' \
	  -e 's|@set M32R|@clear M32R|' \
	  -e 's|@set M680X0|@clear M680X0|' \
	  -e 's|@set MCORE|@clear MCORE|' \
	  -e 's|@set MRI|@clear MRI|' \
	  -e 's|@set PJ|@clear PJ|' \
	  -e 's|@set SH|@clear SH|' \
	  -e 's|@set V850|@clear V850|' \
	  -e 's|@set VAX|@clear VAX|' \
	  -e 's|@set Z8000|@clear Z8000|' \
	  -e 's|@clear IEEEFLOAT|@set IEEEFLOAT|' \
	  -e 's|@clear W32|@set W32|' \
	  -e 's|@set W16|@clear W16|' \
	; \
	grep VERSION= $(GNU_BASE)/gas/configure | \
	  sed -e 's|^|@set |' -e 's|=| |' > gasver.texi; \
	$(TEXI2HTML) as.texinfo; \
	cp as*.html $(ITOOLKIT); \
	egrep -v "@raisesections|@lowersections" < as.html > $(ITOOLKIT)/as.html

$(ITOOLKIT)/gasp.html \
$(ITOOLKIT)/gasp_toc.html: $(GNU_BASE)/gas/doc/gasp.texi
	cd $(ITOOLKIT); $(TEXI2HTML) $<

$(ITOOLKIT)/ld.html \
$(ITOOLKIT)/ld_toc.html: $(GNU_BASE)/ld/ld.texinfo
	cd $(GNU_BUILD); \
	grep VERSION= $(GNU_BASE)/ld/configure | \
	  sed -e 's|^|@set |' -e 's|=| |' > ldver.texi; \
	rm -f bfdsumm.texi; \
	ln -s $(GNU_BASE)/bfd/doc/bfdsumm.texi bfdsumm.texi; \
	rm -f ld.texinfo; \
	ln -s $(GNU_BASE)/ld/ld.texinfo ld.texinfo; \
	rm -f configdoc.texi; \
	cp $(GNU_BASE)/ld/gen-doc.texi configdoc.texi; \
	chmod ugo+w configdoc.texi; \
	$(TEXI2HTML) ld.texinfo; \
	cp ld*.html $(ITOOLKIT)

$(ITOOLKIT)/binutils.html \
$(ITOOLKIT)/binutils_toc.html: $(GNU_BASE)/binutils/binutils.texi
	cd $(ITOOLKIT); \
	rm -f config.texi; \
	ln -s $(GNU_BASE)/binutils/wrs-cfg-binutils.texi config.texi; \
	$(TEXI2HTML) $<; \
	rm -f *.texi

$(ITOOLKIT)/iostream.html: $(GNU_BASE)/libio/iostream.texi
	cd $(ITOOLKIT); $(TEXI2HTML) $<

$(ITOOLKIT)/license.html: $(GNU_BASE)/texinfo/license.texi
	cd $(ITOOLKIT); $(TEXI2HTML) $<

# We aren't configuring/making 'make' for the T3 release, so
# there *is* no build directory
$(IMAKE)/make.html: $(GNU_BASE)/make/make.texinfo
	cd $(IMAKE); $(TEXI2HTML) $<

html_toc: html_dir
#	cp $(GNU_BASE)/toolkit.html $(ITOOLKIT)/index.html

html_dir: 
	test -d $(ITOOLKIT) || mkdir -p $(ITOOLKIT)
	test -d $(IMAKE)    || mkdir -p $(IMAKE)
	test -d $(GNU_BUILD) || mkdir -p $(GNU_BASE)/build_html

uninstall_docs: html_dir
	rm -f $(HTML_DOCS)

endif

# Try to clean out the environment as much as possible here
# before running configure. The aim is that top-level
# makes (that setup a WRS environment) should be exactly
# the same as "low-level" makes run in this directory.

PURGEENV = unset ANSI_INCLUDE_DIR CC CCPP LIBPATH MWABORT MWARCH MWARCH_OS MWCCPP_NAME MWCONFIG_NAME MWCURRENT_LIBPATH MWCURRENT_PATH MWFONT_CACHE_DIR MWHOME MWOS MWSCALABLE_FONTS MWTECHNO MWTHREAD_PHASE1 MWUSE_KERNEL_SHARED_MEMORY MWWITH_OLE OPENWINHOME SHLIB_PATH VX_CPU_FAMILY WIND_BASE HOST WIND_REGISTRY WINHELPPATH X11_INCLUDE_DIR X11_LIB_DIR

# Target(s) built by recursive invocation of `make'.

$(LOCAL_TARGET_DIR)/config.status: configure configure.in Makefile.in
	test -d "$(LOCAL_TARGET_DIR)" || mkdir -p "$(LOCAL_TARGET_DIR)"
	@ echo "Configuring in $(LOCAL_TARGET_DIR)"
	$(PURGEENV) ; cd "$(LOCAL_TARGET_DIR)" && \
		CFLAGS="$(CFLAGS)" \
		CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" \
		CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
		LIBCXXFLAGS_FOR_TARGET="$(LIBCXXFLAGS_FOR_TARGET)" \
		CONFIG_SHELL="$(GNU_CONFIG_SHELL)" \
		LIBGCC2_INCLUDES="$(LIBGCC2_INCLUDES)" \
		$(GNU_CONFIG_SHELL) $(SRC_DIR)/configure \
	    --srcdir=$(SRC_DIR) \
	    --prefix=$(INSTALL_DIR) \
	    --target=$(CANONICAL_TARGET) \
	    --enable-languages="c,c++" \
	    --verbose

# On Windows we need to configure with /bin/bash (sh has `cd' problems)
# but we can't build with bash (with `make all', bash immediately dumps core).
# We therefore require one intermediate target to change the configured-in
# shell, and an extra recursion level to switch shells again.
#
# In subbuilder: Running the GNU_TARGETS one at a time has proven helpful in
# the past; we take the trouble to preserve the exit status of the submake;
# if copying is required, we do it regardless; `late renaming' of products
# is always performed.
#

$(LOCAL_TARGET_DIR)/Makefile.orig: $(LOCAL_TARGET_DIR)/config.status
	$(GNU_BUILD_SHELL) -c 'cd $(LOCAL_TARGET_DIR) && \
	cp Makefile Makefile.orig && \
	sed "s@^[	 ]*SHELL[	 ]*=.*\$$@SHELL=$(GNU_BUILD_SHELL)@" \
		Makefile.orig > Makefile && \
	touch Makefile.orig'
# Why do we still need the 'touch' above?  The 'cp' should have
# changed the timestamp on Makefile.orig... (bc)  

builder: $(LOCAL_TARGET_DIR)/Makefile.orig .neverbuilt
	cd $(LOCAL_TARGET_DIR) && \
		$(MAKE) -f $(SRC_DIR)/makefile SHELL=$(GNU_BUILD_SHELL) \
		subbuilder; \
		echo "==================== FINISHED ===================="

subbuilder:
	exit_status=0 && \
	for gnu_target in $(GNU_TARGETS); do \
		echo "Making \`$$gnu_target' for \`$(CANONICAL_TARGET)'..."; \
		$(MAKE) \
			CFLAGS="$(CFLAGS)" \
			CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" \
			CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
			LIBCXXFLAGS_FOR_TARGET="$(LIBCXXFLAGS_FOR_TARGET)" \
			LIBGCC2_INCLUDES="$(LIBGCC2_INCLUDES)" \
			MAKEINFOFLAGS="--no-validate" \
			LIBGCC1_TEST="null" \
			"$$gnu_target"; \
		exit_status=$$?; \
		test $$exit_status = 0 || break; \
	done; \
	test $(HOST_DIR) != $(LOCAL_HOST_DIR) && $(DIRCOPY); \
	$(MAKE_SCRIPTS) && test -d "$(INSTALL_DIR)/$(CANONICAL_TARGET)/lib/ldscripts" && \
	cp $(INSTALL_DIR)/$(CANONICAL_TARGET)/lib/ldscripts/* $(SCRIPTS_INSTALL); \
	cd $(INSTALL_DIR)/bin && \
		for file in $(CANONICAL_TARGET)*; do \
			test -f $$file && \
			if [ $$file != $(CANONICAL_TARGET)-\* ]; then \
				mv $$file `echo $$file | \
				    sed -e s,$(CANONICAL_TARGET)-,, \
				    -e 's,$(EXE)$$,$(TARGET_SUFFIX)$(EXE),' \
				    -e 's,^gcc,cc,'` ; \
			fi; \
		done; \
	exit $$exit_status

.neverbuilt:

